

package orest.back.achieve;
import orest.common.response.Response;
import orest.common.valueobject.KjcgVal;
import orest.common.dao.KjcgDao;
import java.util.*;
/**
 *
 * @author admin
 */
public class KjcgAction {

     public KjcgAction() {
    }

  

      public boolean setChannelShow(String kjcgid,String ifshow) {
    	KjcgDao obj = new KjcgDao();
        boolean exe = true;
        exe = obj.setChannelShow (kjcgid,ifshow);
    	return exe;
    }


       public boolean SetChannelShow_Batch(String ifshow,String[] id) {
    	KjcgDao obj = new KjcgDao();
    	return obj.SetChannelShow_Batch(ifshow,id);
    }

    

     


      public String findKjcgByCondition(String key, int pageNo,
                                                      int pageRecords, long ttl) {

        Response            rp       = new Response();
        StringBuffer        result   = new StringBuffer();
        KjcgDao        obj      = new KjcgDao();
    
        boolean            opReturn = true;
        String              temp     = "";
        long                total    =0;



        result.append ("<?xml version='1.0' encoding='GBK'?>");
        result.append ("<root>");

        /**
         * execute query and get data that were packed in entity bean and
         * saved in arraylist object.
         */



        try{
            if(pageNo <= 1 || (pageNo > 1 && ttl == 0))
            {
               total = obj.countKjcgByCondition(key,rp);
            }
            else
                total = ttl;
            opReturn = obj.findKjcgShowByConditon(rp,key,pageNo, pageRecords,(int)total) ;
            if(!opReturn)
                return null;
        }
        catch(Exception e) {
            e.printStackTrace();
        }


        result.append("<total>");
        result.append(total);
        result.append("</total>");

    
        ArrayList al = rp.getValObjs ();
        Iterator iterator = al.iterator ();
        try{
            while(iterator.hasNext ()){
                KjcgVal objElem = (KjcgVal)iterator.next();
                
                result.append ("<record>");

             

                result.append ("<KjcgID>");
                result.append (objElem.getKjcgID());
                result.append ("</KjcgID>");
                result.append ("<Kjcg_Item_3><![CDATA[");
                result.append (objElem.getKjcg_Item_3().trim());
                result.append ("]]></Kjcg_Item_3>");
                result.append ("<UnitID>");
                result.append (objElem.getUnitID());
                result.append ("</UnitID>");
                result.append ("<Kjcg_Item_9><![CDATA[");
                result.append (objElem.getKjcg_Item_9());
                result.append ("]]></Kjcg_Item_9>");
                result.append ("<Kjcg_Item_Year>");
                result.append (objElem.getKjcg_Item_Year());
                result.append ("</Kjcg_Item_Year>");
                result.append ("<ChannelShow>");
                result.append (objElem.getChannelShow());
                result.append ("</ChannelShow>");
                result.append ("<HomepageShow>");
                result.append (objElem.getHomepageShow());
                result.append ("</HomepageShow>");
                             
                result.append ("</record>");
                objElem = null;
            }
        }
        catch(Exception e) {
            System.out.println ("when encoding the string, exception occured.");
            System.out.println ("The class is KjcgAction and the function is " +
                                 "findKjcgByCondition");
        }

        result.append ("</root>");

        al = null;
        obj = null;
        rp = null;
   

        return result.toString ();

    }

   

     

   

}
